package com.example.demo.demos.web.Controller;

import com.example.demo.demos.web.Services.DataHandleService;
import com.example.demo.demos.web.po.CommonData;
import com.example.demo.demos.web.po.ReportData;
import com.example.demo.demos.web.po.SystemData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @BelongsProject: demo1
 * @BelongsPackage: com.example.demo.demos.web.Controller
 * @Author: Hu1er
 * @CreateTime: 2023-07-03  09:56
 * @Description: TODO
 * @Version: 1.0
 */

@Controller
public class DataHandleController {
    @Autowired
    DataHandleService dataHandleService;
    /**
     * @Description 插入CommonData
     * @author Hu1er
     * @version 1.17.0
     * @date 2023/7/3
     */
    @PostMapping("/CommonData/insertAndShow")
    public String insertCommonData(CommonData commonData){
        if (commonData != null) {
            int result = dataHandleService.insertCommonData(commonData);
            if (result != 0) {
                return String.format("成功插入CommonData%d条",result);
            }
        }
        return null;
    }
    /**
     * @Description 插入SystemData数据后，自动根据客户名称查systemData，用于界面显示
     * @author Hu1er
     * @version 1.17.0
     * @date 2023/7/3
     */
    @PostMapping("/SystemData/insertAndShow")
    public List<String> insertSystemData(SystemData systemData){
        if (systemData != null) {
            int result = dataHandleService.insertSystemData(systemData);
            if (result != 0) {
                String customName = systemData.getCustomname();
                if (customName != null) {
                    return dataHandleService.selectSystemNameByCustomName(customName);
                }
            }
        }
        return null;
    }
    /**
     * @Description 插入reportData数据后，自动根据客户名称查漏洞信息，用于界面显示
     * @author Hu1er
     * @version 1.17.0
     * @date 2023/7/3
     */
    @PostMapping("/ReportData/insertAndShow")
    public List<ReportData> insertReportData(ReportData reportData){
        if (reportData != null) {
            int result =  dataHandleService.insertReportdata(reportData);
            if (result != 0) {
                String customName = reportData.getCustomname();
                if (customName != null) {
                    return  dataHandleService.selectVulninfoByCustomName(customName);
                }
            }
        }
        return null;
    }
    /**
     * @Description 用于下拉框，展示系统名称
     * @author Hu1er
     * @version 1.17.0
     * @date 2023/7/3
     */
    @PostMapping("/SystemData/ShowSystemName")
    public List<String> showSystemName(String customName){
        if (customName != null) {
            return dataHandleService.showSystemNameByCustomName(customName);
        }
        return null;
    }

}

